#include "EditWindow.h";

EditWindow::EditWindow(SdkTrayManager *mTrayMgr)
{
	this->mTrayMgr = mTrayMgr;

	emitterWindowVisible = false;

	windowCaption = mTrayMgr->createLabel(OgreBites::TL_LEFT, "TEditWindowCaption", "Edit scene:", 350);

	menuItemsActivities.push_back("Create new object");
	menuItemsActivities.push_back("Edit existing actors");
	menuItemsActivities.push_back("Edit terrain");
	mActivityMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_LEFT, "TActivityMenu", "Activity:", 350, 200, 3, menuItemsActivities);

	menuItemsObjects.push_back("Box group (PhysX test)");
	menuItemsObjects.push_back("Block 1");
	menuItemsObjects.push_back("Block 2");
	menuItemsObjects.push_back("Block 3");
	menuItemsObjects.push_back("House 1");
	menuItemsObjects.push_back("House 2");
	menuItemsObjects.push_back("Tree 1");
	menuItemsObjects.push_back("Tree 2");
	menuItemsObjects.push_back("Lake 1");
	menuItemsObjects.push_back("Lake 2");
	menuItemsObjects.push_back("Lake 3");
	menuItemsObjects.push_back("Attach water emitter");
	mObjectMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_LEFT, "TObjectMenu", "Object type:", 350, 200, 10, menuItemsObjects);
	mHolderActorMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_LEFT, "THolderActorMenu", "Attach to actor:", 350, 200, 10, menuItemsHolderActors);
	
	mActorMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_LEFT, "TActorMenu", "Actors:", 350, 200, 10, menuItemsActors);
	helpText0 = mTrayMgr->createLabel(OgreBites::TL_LEFT, "THelpText0", "Create object: right click", 350);
	helpText1 = mTrayMgr->createLabel(OgreBites::TL_LEFT, "THelpText1", "Move selected: I,J,K,L, up/down: U,O", 350);
	helpText2 = mTrayMgr->createLabel(OgreBites::TL_LEFT, "THelpText2", "Scale selected: N8,N2, rotate: N4,N6", 350);
	helpText4 = mTrayMgr->createLabel(OgreBites::TL_LEFT, "THelpText4", "Edit elevations: +,-", 350);
	helpText5 = mTrayMgr->createLabel(OgreBites::TL_LEFT, "THelpText5", "Update terrain: END", 350);
	mResetButton = mTrayMgr->createButton(OgreBites::TL_LEFT,"TResetButton","Reset scene",200);
	mSaveCameraButton = mTrayMgr->createButton(OgreBites::TL_LEFT,"TSaveCameraButton","Save camera",200);
	mSaveButton = mTrayMgr->createButton(OgreBites::TL_LEFT,"TSaveButton","Save scene",200);

	//--

	subWindowCaption = mTrayMgr->createLabel(OgreBites::TL_BOTTOM, "TEmitterWindowCaption", "Edit attached emitters:", 350);
	mEmitterMenu = mTrayMgr->createLongSelectMenu(OgreBites::TL_BOTTOM, "TEmitterMenu", "Emitters:", 350, 200, 10, menuItemsEmitters);
	helpText3 = mTrayMgr->createLabel(OgreBites::TL_BOTTOM, "THelpText3", "Move selected: arrows, up/down: N1,N0", 350);
}

//------------------------------------------------------------------------------------------

EditWindow::~EditWindow(void)
{
}

//-------------------------------------------------------------------------------------------

void EditWindow::show(void)
{
	mTrayMgr->moveWidgetToTray(windowCaption,OgreBites::TL_LEFT);
	windowCaption->show();
	mTrayMgr->moveWidgetToTray(mActivityMenu,OgreBites::TL_LEFT);
	mActivityMenu->show();

	if(mActivityMenu->getSelectionIndex() == Activity_Create)
	{
			mTrayMgr->moveWidgetToTray(mObjectMenu,OgreBites::TL_LEFT);
			mObjectMenu->show();
			if(mObjectMenu->getSelectionIndex() == Object_WaterEmitter)
			{
				mTrayMgr->moveWidgetToTray(mHolderActorMenu,OgreBites::TL_LEFT);
				mHolderActorMenu->show();
			}
			mTrayMgr->moveWidgetToTray(helpText0,OgreBites::TL_LEFT);
			helpText0->show();
	}
	else if(mActivityMenu->getSelectionIndex() == Activity_Edit)
	{
			mTrayMgr->moveWidgetToTray(mActorMenu,OgreBites::TL_LEFT);
			mActorMenu->show();
			mTrayMgr->moveWidgetToTray(helpText1,OgreBites::TL_LEFT);
			helpText1->show();
			mTrayMgr->moveWidgetToTray(helpText2,OgreBites::TL_LEFT);
			helpText2->show();

			if(emitterWindowVisible)
			{
				mTrayMgr->moveWidgetToTray(subWindowCaption,OgreBites::TL_BOTTOM);
				subWindowCaption->show();
				mTrayMgr->moveWidgetToTray(mEmitterMenu,OgreBites::TL_BOTTOM);
				mEmitterMenu->show();
				mTrayMgr->moveWidgetToTray(helpText3,OgreBites::TL_BOTTOM);
				helpText3->show();
			}
	}
	else if(mActivityMenu->getSelectionIndex() == Activity_EditTerrain)
	{
			mTrayMgr->moveWidgetToTray(helpText4,OgreBites::TL_LEFT);
			helpText4->show();
			mTrayMgr->moveWidgetToTray(helpText5,OgreBites::TL_LEFT);
			helpText5->show();
			mTrayMgr->moveWidgetToTray(mSaveCameraButton,OgreBites::TL_LEFT);
			mSaveCameraButton->show();
			mTrayMgr->moveWidgetToTray(mSaveButton,OgreBites::TL_LEFT);
			mSaveButton->show();
	}

	mTrayMgr->moveWidgetToTray(mResetButton,OgreBites::TL_LEFT);
	mResetButton->show();
}

//-------------------------------------------------------------------------------------------

void EditWindow::showEmitterWindow(bool show)
{
	emitterWindowVisible = show;
}

//-------------------------------------------------------------------------------------------
void EditWindow::hide(void)
{
    mTrayMgr->removeWidgetFromTray(windowCaption);
	windowCaption->hide();
	mTrayMgr->removeWidgetFromTray(mActivityMenu);
	mActivityMenu->hide();
    mTrayMgr->removeWidgetFromTray(mObjectMenu);
	mObjectMenu->hide();
	mTrayMgr->removeWidgetFromTray(mHolderActorMenu);
	mHolderActorMenu->hide();
    mTrayMgr->removeWidgetFromTray(helpText0);
	helpText0->hide();
    mTrayMgr->removeWidgetFromTray(mActorMenu);
	mActorMenu->hide();
    mTrayMgr->removeWidgetFromTray(helpText1);
	helpText1->hide();
    mTrayMgr->removeWidgetFromTray(helpText2);
	helpText2->hide();
    mTrayMgr->removeWidgetFromTray(helpText4);
	helpText4->hide();
    mTrayMgr->removeWidgetFromTray(helpText5);
	helpText5->hide();
	mTrayMgr->removeWidgetFromTray(subWindowCaption);
	subWindowCaption->hide();
    mTrayMgr->removeWidgetFromTray(mEmitterMenu);
	mEmitterMenu->hide();
    mTrayMgr->removeWidgetFromTray(helpText3);
	helpText3->hide();
	mTrayMgr->removeWidgetFromTray(mResetButton);
	mResetButton->hide();
	mTrayMgr->removeWidgetFromTray(mSaveCameraButton);
	mSaveCameraButton->hide();
	mTrayMgr->removeWidgetFromTray(mSaveButton);
	mSaveButton->hide();
}

//-------------------------------------------------------------------------------------------

EditWindow::eActivityType EditWindow::getActivitySelection(void)
{
	return (eActivityType)mActivityMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------------

EditWindow::eObjectSelection EditWindow::getObjectSelection(void)
{
	return (eObjectSelection)mObjectMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------------

int EditWindow::getActorSelection(void)
{
	return mActorMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------------

int EditWindow::getHolderActorSelection(void)
{
	return mHolderActorMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------------

int EditWindow::getEmitterSelection(void)
{
	return mEmitterMenu->getSelectionIndex();
}

//-------------------------------------------------------------------------------------------

void EditWindow::refresh(void)
{
	hide();
	show();
}

//-------------------------------------------------------------------------------------------

void EditWindow::injectActorNames(Ogre::StringVector actorNames)
{
	mActorMenu->setItems(actorNames);
}

//-------------------------------------------------------------------------------------------

void EditWindow::injectHolderActorNames(Ogre::StringVector holderActorNames)
{
	mHolderActorMenu->setItems(holderActorNames);
}

//-------------------------------------------------------------------------------------------

void EditWindow::injectEmitterNames(Ogre::StringVector emitterNames)
{
	mEmitterMenu->setItems(emitterNames);
}